package com.dot;

import com.dot.comm.utils.MySQLSyncUtil;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.yaml.snakeyaml.Yaml;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Map;

@ComponentScan(basePackages = {"com.dot.msg", "com.dot.sys", "com.dot.deepseek", "com.dot.comm.config", "com.dot.comm.manager", "com.dot.comm.exception"})
@MapperScan(basePackages = {"com.dot.msg.*.dao", "com.dot.deepseek.dao"})
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class DotChatApplication {


    public static void main(String[] args) {
        try {//同步mysql表结构
            Yaml yaml = new Yaml();
            String path = DotChatApplication.class.getClassLoader().getResource("").getPath() + "application.yml";
            InputStream inputStream = new FileInputStream(path);
            Map<String, Object> yml = (Map<String, Object>) yaml.load(inputStream);
            Map<String, Object> spring = (Map<String, Object>) yml.get("spring");
            Map<String, Object> datasource = (Map<String, Object>) spring.get("datasource");
            Map<String, Object> druid = (Map<String, Object>) datasource.get("druid");
            String url = String.valueOf(druid.get("url"));
            String username = String.valueOf(druid.get("username"));
            String password = String.valueOf(druid.get("password"));
            MySQLSyncUtil.update(url, username, password);
        } catch (Exception e) {
            e.printStackTrace();
        }
        SpringApplication.run(DotChatApplication.class, args);
    }
}
